/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: SmsCodeAuthenticationToken
 * Author:   zhouheng
 * Date:     2019/6/16 14:26
 * Description: 手机号验证码组装token
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhouh.golden.security.code.sms;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * 〈一句话功能简述〉<br> 
 * 〈手机号验证码组装token〉
 *
 * @author zhouheng
 * @create 2019/6/16
 * @since 1.0.0
 */
public class SmsCodeAuthenticationToken extends AbstractAuthenticationToken {

    private Object principal;

    SmsCodeAuthenticationToken(String mobile) {
        super(null);
        this.principal = mobile;
        setAuthenticated(false);
    }

    SmsCodeAuthenticationToken(Object principal, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        super.setAuthenticated(true);
    }

    /**
     * Creates a token with the supplied array of authorities.
     *
     * @param authorities the collection of <tt>GrantedAuthority</tt>s for the principal
     *                    represented by this authentication object.
     */
    public SmsCodeAuthenticationToken(Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return principal;
    }
}